import 'package:calendar_date_picker2/calendar_date_picker2.dart';
import 'package:chathouse/constant/my_color.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:chathouse/util/base_utils.dart';

typedef DatePickWidget8ItemChange = Function(DateTime val);

//問題類型8 日期選擇
class DatePickWidget8 extends StatefulWidget {
  String? title;
  DateTime? initDateTime;
  DatePickWidget8ItemChange itemChange;

  bool request;

  DatePickWidget8(this.title, this.initDateTime, this.itemChange,
      {this.request = false, Key? key})
      : super(key: key);

  @override
  State<DatePickWidget8> createState() => _DatePickWidget8State();
}

class _DatePickWidget8State extends State<DatePickWidget8> {
  @override
  Widget build(BuildContext context) {
    return Container(
        padding: EdgeInsets.only(left: 26.w, right: 26.w),
        child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
          Row(crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              widget.request
                  ? Text(
                      "*",
                      style: getTextStyle(18.sp, color: Colors.red),
                    )
                  : Container(),
              Expanded(
                  child: Text(
                widget.title ?? "",
                style: getTextStyle(18.sp, color: Colors.black),
              ))
            ],
          ),
          SizedBox(
            height: 2.w,
          ),
          //
          CalendarDatePicker2(
            initialValue:
                widget.initDateTime == null ? [] : [widget.initDateTime],
            config: CalendarDatePicker2Config(
                centerAlignModePickerButton: true,
                customModePickerButtonIcon: const SizedBox(),
                calendarType: CalendarDatePicker2Type.single,
                calendarViewMode: DatePickerMode.day,
                weekdayLabelTextStyle: getTextStyle(16.sp, color: Colors.black),
                dayTextStyle: getTextStyle(16.sp, color: Colors.black),
                selectedDayHighlightColor: MyColors.green_69157608,
                firstDate: DateTime.now()),
            onValueChanged: (val) {
              widget.itemChange(val.first!);
            },
          ),
        ]));
  }
}
